<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: Circle.php
 * Date: 2017/1/2
 * Time: 23:13
 */

namespace app\home\model\page\management;

use app\api\model\dao\Circle;
use app\api\model\dao\DashangGift;
use app\api\model\dao\RecommendRank;
use app\home\model\UserAccount;
use app\library\Error;
use app\library\Flag;
use app\library\PageBase;
use think\Exception;
use think\Validate;

class UpdateDashangGift extends PageBase
{
    private $objDashangGift;

    public function __construct()
    {
        parent::__construct();

        $this->objDashangGift = new DashangGift();
    }

    /**
     * @param $param
     * @return array|bool
     * @DESC 验证接口字段
     */
    public function checkParam($param)
    {
        $rule = [
            'id' => 'require',
            'type' => 'require|in:0,1,2',
        ];
        $msg = [
            'id.require' => '请填写打赏ID',
            'type.require' => '请填写类型',
        ];

        $validate = new Validate($rule, $msg);
        $result = $validate->check($param);
        if (!$result) {
            return $validate->getError();
        }
        return '';
    }

    public function excute($param)
    {
//        $ret = $this->checkToken($param);
//        if (false === $ret) {
//            throw new Exception('check token fail...', Error::ERR_SYS);
//        }

        // 1、参数校验
        $ret = $this->checkParam($param);
        if ($ret) {
            return $this->getRes(Error::ERR_PARAM, $ret);
        }

        if ('0' == $param['type']) {
            $ret = $this->objDashangGift->delDashangGiftByid($param['id']);
        }
        if ('1' == $param['type']) {
            $ret = $this->objDashangGift->upDashangGift($param['id']);
        }
        if ('2' == $param['type']) {
            $ret = $this->objDashangGift->downDashangGift($param['id']);
        }
        if (false === $ret) {
            return $this->getRes(Error::ERR_SYS);
        }
        return $this->getRes();
    }
}
